using DL.Tools;
using System.Net.Sockets;
using UnityEngine;
namespace ServerBase.Base
{
    public class SocketAsyncEventArgsPool : SingletonNoMono<SocketAsyncEventArgsPool>
    {
        private ObjectPool<SocketAsyncEventArgs> _pool;

        private int GetCount = 0;
        private int ReturnCount = 0;

        public SocketAsyncEventArgsPool()
        {
            _pool = new(() => new(), null, null, (e) => e.Dispose(), true, 10, 100);
        }

        public SocketAsyncEventArgs Get()
        {
            Debug.Log($"获取一次SocketAsyncEventArgs,总次数{++GetCount}");
            return _pool.Get();
        }

        public void Return(SocketAsyncEventArgs e) 
        {
            Debug.Log($"回收一次SocketAsyncEventArgs,总次数{++ReturnCount}");
            _pool.Return(e);
        }

        public void Destroy() => _pool.Dispose();

        public void AllReturn() => _pool.AllReturn();

        public int AllCount => _pool.AllCount;

        public int UsableCount => _pool.UsableCount;
    }
}